package com.jbm.enterapplication.moduserpwd.presenter

import android.content.Context
import android.view.View
import com.jbm.enterapplication.InterfaceMa
import com.jbm.enterapplication.moduserpwd.mode.Chang_mode_Pwd
import com.jbm.enterapplication.moduserpwd.view.Chang_View_Pwd_In
import com.jbm.enterapplication.sharedprefer.SharedPreActivity
import com.jbm.enterapplication.utlisclass.Constant
import com.jbm.enterapplication.utlisclass.ExitActivity
import com.jbm.enterapplication.view.DialogLoading
import com.jbm.enterapplication.view.DoubleButtonDialog

/**
 * Created by 家帮忙 on 2017/9/5.
 */
class Chang_Presenter_Pwd :Chang_Presenter_Pwd_In{
    var context:Context?=null
    var changmodepwd:Chang_mode_Pwd?=null
    var changpresenterpwd:Chang_View_Pwd_In?=null
    var shandprefter: SharedPreActivity?=null
    constructor(context: Context?, changpresenterpwd: Chang_View_Pwd_In?) {
        this.context = context
        this.changpresenterpwd = changpresenterpwd
        changmodepwd= Chang_mode_Pwd()
        shandprefter= SharedPreActivity(context)
    }
    var  dialogLoading: DialogLoading?=null
    override fun getModiMiMa() {

        if (changpresenterpwd?.getPwdJm().equals("")){
            changpresenterpwd!!.getPwdJmErr().error = "密码不能为空"
            return
        }else if(changpresenterpwd?.getPwdJm()?.length!! <6){
            changpresenterpwd!!.getPwdJmErr().error = "密码长度不符"
            return
        }else if( changpresenterpwd?.getPwdXm().equals("")){
            changpresenterpwd!!.getPwdXmErr().error = "密码不能为空"
            return
        }else if(changpresenterpwd?.getPwdQm().equals("")){
            changpresenterpwd?.getPwdQmErr()?.error = "密码不能为空"
            return
        }else{
            dialogLoading = DialogLoading(context!!, "修改中.....", true)
            dialogLoading?.show()
        changmodepwd?.setModiMiMa(changpresenterpwd?.getPwdJm()!!, changpresenterpwd?.getPwdXm()!!, changpresenterpwd?.getPwdQm()!!,object :InterfaceMa<String>{
            override fun onSuccess(t: String, boolean: Boolean) {
                if (boolean==true){
                    setExitUser("修改密码成功，退出后重新加载")
                }

            }

            override fun setError(err: String, boolean: Boolean) {
                if (boolean==false){
                    hint(err)
                }

            }

        })
    }
}


    //一些提示的时候调用
    fun hint(name: String) {
        val dialog = DoubleButtonDialog(context, name)
        dialog.getokbtn().setOnClickListener(View.OnClickListener { dialog.dismiss() })
        dialog.setisVisibility()

    }
    //一些提示的时候调用
    fun setExitUser(name: String) {

        val dialog = DoubleButtonDialog(context, name)
        dialog.getokbtn().setOnClickListener {
            shandprefter?.ExitUser()
            ExitActivity.getInstanst().exitActivity()
//            startActivity(Intent(this@OpenDoor,UserLogin ::class.java))
            Constant.isWXLogin=false
            dialog.dismiss()
        }
        dialog.setisVisibility()

    }
}